package com.zero.util;

import com.zero.entity.Family;
import com.zero.entity.FamilyMember;
import java.math.BigDecimal;

public class SystemUtils {

    //检查并确认成员的资产不少于0
    public static void checkMemberAsseets(FamilyMember familyMember){
        if (familyMember == null || familyMember.getAssets() == null || familyMember.getDebt() == null)
            return ;
        if (familyMember.getAssets().compareTo(new BigDecimal(0)) < 0){
            familyMember.setDebt(familyMember.getDebt().subtract(familyMember.getAssets()));
            familyMember.setAssets(new BigDecimal(0));
        }
    }

    //检查并确认个人资产不少于0
    public static void checkFamilyAssets(Family family){
        if (family == null || family.getAssets() == null || family.getDebt() == null)
            return ;
        if (family.getAssets().compareTo(new BigDecimal(0)) < 0){
            family.setDebt(family.getDebt().subtract(family.getAssets()));
            family.setAssets(new BigDecimal(0));
        }
    }




}
